#include <stdio.h>
#include <string.h>
#include "algo_insertionSort.h"

#define numElement 10

void insertionSort(int a[], int length) {
	int key, i, j;
	for (i = 1; i < length; i++) {
		key = a[i];
		for (j = i-1; (j >= 0) && (key < a[j]); j--) {
			a[j+1] = a[j];
		}
		a[j+1] = key;
	}
}

void test_algo_insertionSort() {
	int data[numElement] = { 12, 1, 3, 6, 9, 8, 2, 7, 10, 15 };

	printf("Before sorting.\n");
	for (int i = 0; i < numElement; i++) {
		printf("%d", data[i]);
		if ( i < numElement - 1 )
			printf(", ");
		else
			printf("\n");
	}
	printf("\n");
	insertionSort(data, numElement);
	printf("After insertion sorting.\n");
	for (int i = 0; i < numElement; i++) {
		printf("%d", data[i]);
		if ( i < numElement - 1 )
			printf(", ");
		else
			printf("\n");
	}
}
